﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CMN.BLL;
using CMN.Common;
using CMN.Entity;
using CMN.Models.Interfaces;
namespace CMN.Models
{
    /// <summary>
    /// 文章Service
    /// </summary>
    public class Module_ArticleService: IDataService<Module_ArticleEntity>,IUpdateDataService<Module_ArticleEntity>
    {
        /// <summary>
        /// 新增文章
        /// </summary>
        /// <param name="Module_ArticleEntity"></param>
        /// <returns>bool</returns>
        public string Insert(Module_ArticleEntity module_articleEntity)
        {
            module_articleEntity.DataTable_Action = DataTableAction.Insert;
            Module_Article bll = new Module_Article();
            if (bll.InsertUpdateDelete(module_articleEntity) > 0)
            {
                return "";
            }
            else
            {
                return "失败";
            }
        }

        /// <summary>
        /// 返回文章查询列表
        /// </summary>
        /// <param name="qp"></param>
        /// <param name="count">查询总个数</param>
        /// <returns>List</returns>
        public List<Module_ArticleEntity> List(QueryParam qp,out int count)
        {
            Module_Article bll = new Module_Article();
            return bll.List(qp, out count);
        }

        /// <summary>
        /// 更新文章
        /// </summary>
        /// <param name="Module_Article"></param>
        /// <returns>bool</returns>
        public string Update(Module_ArticleEntity module_articleEntity)
        {
            Module_Article bll = new Module_Article();
            module_articleEntity.DataTable_Action = DataTableAction.Update;
            if (bll.InsertUpdateDelete(module_articleEntity) > 0)
            {
                return "";
            }
            else
            {
                return "失败";
            }
        }

        /// <summary>
        /// 删除文章
        /// </summary>
        /// <param name="Module_Article"></param>
        /// <returns>bool</returns>
        public string Delete(Module_ArticleEntity module_articleEntity)
        {
            Module_Article bll = new Module_Article();
            module_articleEntity.DataTable_Action = DataTableAction.Delete;
            if (bll.InsertUpdateDelete(module_articleEntity) > 0)
            {
                return "";
            }
            else
            {
                return "失败";
            }
        }

        /// <summary>
        /// 批量删文章
        /// </summary>
        /// <param name="idList">删除id列表  2_8_9_45</param>
        /// <returns>bool</returns>
        public string DeleteList(string idList)
        {
            Module_Article bll = new Module_Article();
            string[] list =Utils.SplitString(idList,"_");
            string strDel=Utils.ArrayToString(list,",",false);
            if (bll.DelList(strDel) > 0)
            {
                return "";
            }
            else
            {
                return "失败";
            }

        }

        /// <summary>
        /// 返回单个文章
        /// </summary>
        /// <param name="id"></param>
        /// <returns>Module_ArticleEntity</returns>
        public Module_ArticleEntity Look(int id)
        {
            Module_Article bll = new Module_Article();
            return bll.Disp(id);
        }

        public string UpdateList(string idList, string values)
        {
            Module_Article bll = new Module_Article();
            string[] list = Utils.SplitString(idList, "_");
            string strList = Utils.ArrayToString(list, ",", false);
            string where = string.Concat(" id in (", strList, ") ");
            if (bll.UpdateList(values,where) > 0)
            {
                return "";
            }
            else
            {
                return "失败";
            };
        }
    }
}
